import { ref, watch } from "vue"
export default function (key, value) {
  let data = ref(value)

  if (value) {
    // 存
    window.localStorage.setItem(key, JSON.stringify(value))
  } else {
    // 取
    data.value = JSON.parse(window.localStorage.getItem(key))
  }

  watch(data, (newValue) => {
    window.localStorage.setItem(key, JSON.stringify(newValue))
  })

  return data;
}